from flask import Flask,request,render_template
import json
from MySQLHelper import MySQLHelper
app = Flask(__name__,static_folder="static",template_folder="templates1")
@app.route("/register",methods=["post"])
def register():
    '''register'''
    conn=MySQLHelper();
    sql="insert into tb_user values(null,%s,md5(%s),%s)"
    i=conn.executeForUCD(sql,[request.form.get("uname"),request.form.get("upwd"),0])
    if i>0 :
        return "1"
    else:
        return "0"


@app.route("/login",methods=["post"])
def login():
    '''这是个登录功能'''
    uname=request.form.get("l_uname","")
    upwd=request.form.get("l_upwd","")
    print(request.form.__str__())
    conn=MySQLHelper();
    sql="select * from tb_user where uname=%s and upwd=md5(%s)"
    rs=conn.executeForSelectAll(sql,(uname,upwd))
    i=rs.__len__()
    print(i)
    if i==0:
        return "0"#同步请求 fault
    else:
        return "1"  # success

@app.route("/manager")
def manager():
    return render_template("admin.html")

@app.route('/',methods=["get","post"])
def index():
    # str= request.args.__str__()
    # print(str)
    # print(request.path)
    # print(request.full_path)
    # print(request.args.get("upwd"))
    # print(request.args.getlist("upwd"))
    # print(request.args.get("age",0))
    # # print(Flask.__doc__)
    # # print(app.__version__)
    # print(request.headers)
    #
    # print(request.form.__str__())
    # print(request.form.get("admin",""))

    return render_template("index.html")

@app.route("/welcome")
def welcome():
    return  render_template("welcome.html")

@app.route("/articleList")
def articleList():
    return  render_template("articleList.html")

@app.route("/analysis")
def analysis():
    return  render_template("analysis.html")
if __name__ == '__main__':
    app.run(host="localhost",port=80,debug=True)
